package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.EquipmentAcceptance;
import com.amsp.oa.oademo.service.EquipmentAcceptanceService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/api/equipment-acceptance")
@CrossOrigin
@Api(tags = "设备验收记录")
public class EquipmentAcceptanceController {

    @Autowired
    private EquipmentAcceptanceService equipmentAcceptanceService;

    @PostMapping("/save")
    @ApiOperation("保存设备验收记录")
    public boolean save(@RequestBody EquipmentAcceptance equipmentAcceptance) {
        return equipmentAcceptanceService.saveWithAccessories(equipmentAcceptance);
    }

    @GetMapping("/list")
    @ApiOperation("分页查询设备验收记录")
    public Page<EquipmentAcceptance> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String equipmentName,
            @RequestParam(required = false) String specificationModel,
            @RequestParam(required = false) String equipmentNumber,
            @RequestParam(required = false) String acceptancePerson,
            @RequestParam(required = false) LocalDate startDate,
            @RequestParam(required = false) LocalDate endDate) {
        return equipmentAcceptanceService.getPage(current, size, equipmentName, specificationModel,
                equipmentNumber, acceptancePerson, startDate, endDate);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询设备验收记录")
    public EquipmentAcceptance getById(@PathVariable Long id) {
        return equipmentAcceptanceService.getDetailById(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据ID删除设备验收记录")
    public boolean delete(@PathVariable Long id) {
        return equipmentAcceptanceService.removeById(id);
    }
}